﻿package com.crl.core.config.section.model
{
	import com.crl.core.config.ConfigurationManager;
	
	
	

	/**
	 * ...
	 * @author crl
	 */
	public class ConnectionStringSetting
	{
		public var name:String;
		public var connectionString:String;
		public var providerName:String;
		public function ConnectionStringSetting() 
		{
		}
		
		public function parse(xml:XML):void{
			this.name = xml.@name;
			
			var conn:String= xml.@connectionString;
			
			
			var reg:RegExp=new RegExp("\\{(\\w+)\\}","g");
			
			conn=conn.replace(reg,replaceFunc)
			
			this.connectionString=conn;
			this.providerName = xml.@provider;
		}
		
		
		private function replaceFunc():String{
			
			var key:String=arguments[1]
			if(key in ConfigurationManager.appSetting){
				return ConfigurationManager.appSetting[key];
			}

			return key;
		}
	}

}